#ifndef SCHEADER_H_
#define SCHEADER_H_

#include <memory>
#include <list>
#include <vector>
#include <map>
#include <string>
#include <sstream>
#include <QtGlobal>
#include <Trc.h>

#define PI 3.1415926535897932384626433832795
#define VERSION_MAJOR 0
#define VERSION_MINOR 1
#define VERSION_BUILD 0

#define EXC_UNKNOWNTRANSACTION 1000
#define EXC_LOCALCONFAILED 2000

// Qt
class QObject;
class QString;
class QBuffer;
class QWidget;
class QAction;
class QTimer;
class QHttp;
class QAuthenticator;
class QNetworkProxy;
class QHttpResponseHeader;
class QSslError;
class QXmlStreamWriter;
class QXmlParseException;
class QXmlAttributes;

// SQLite
struct sqlite3;
struct sqlite3_stmt;
typedef qlonglong PkType;
typedef std::vector<PkType> Pks;

// DB general
#define MAX_FK_PER_TABLE	3
#define DB_COL_PK	0
#define DB_COLT_PK	"_0"
#define DB_COL_LUT	1
#define DB_COLT_LUT	"_1"
#define DB_COL_IK	2
#define DB_COLT_IK	"_2"
#define DB_COL_IKS	3
#define DB_COLT_IKS	"_3"
#define DB_COL_IKS2	4
#define DB_COLT_IKS_	"_4"
#define PK_UNDEF		0
#define EID_M_ENTITIES	1
#define M_ENTITIES_PK		0
#define M_ENTITIES_TNAME	1
#define M_ENTITIES_NAME		2
#define M_ENTITIES_TRNAME	3
#define M_ENTITIES_RNAME	4
#define M_ENTITIES_DOMAIN	5
#define EID_M_ATTRS		2
#define M_ATTRS_PK			0
#define M_ATTRS_FPKENT		1
#define M_ATTRS_FUNCTION	2
#define M_ATTRS_TARGET		3
#define M_ATTRS_DTYPE		4
#define M_ATTRS_TNAME		5
#define M_ATTRS_NAME		6
#define DATETIME_TECH "yyyy MM dd hh mm ss"
#define DATETIME_USER "d.MMM.yy hh:mm"
typedef signed long TimeType;
#define TIME_MIN	((TimeType)0)
#define TIME_MAX	((TimeType)2147483647)
// static convenience objects QDateTime with min and max values are defined in DataModel.h
namespace sybilpm
{
/*
possible values for "function"
1=PK
2=identity key (IK)
3=identity sorting attribute one ("from" or version)
4=identity sorting attribute two ("to")
5=foreign PK, see target for target table
6=foreign IK, see target for target table
7=payload, no special function
*/
enum AttrFunct
{
	AFUNCT_UNDEF=0,
	AFUNCT_PK	=1,
	AFUNCT_IK	=2,
	AFUNCT_IKS	=3,
	AFUNCT_IKS2	=4,
	AFUNCT_FPK	=5,
	AFUNCT_FIK	=6,
	AFUNCT_DATA	=7,
	AFUNCT_LUT  =8
};
enum AttrDtype
{
	ADTYPE_UNDEF	=0,
	ADTYPE_I32S		=3,
	ADTYPE_F64		=12,
	ADTYPE_STRASC	=20,
	ADTYPE_STRUTF8	=21,
	ADTYPE_DBKEY	=30,
	ADTYPE_DATIM	=31
};

enum DataDomain
{
	DOMAIN_UNDEF = 0,
	DOMAIN_METADATA,	// 1
	DOMAIN_DATA,		// 2
	DOMAIN_DATATL,		// 3
	DOMAIN_DATAVS,		// 4
	DOMAIN_ACTION
};

enum ScopeType
{
	SCOPE_UNDEF = 0,
	SCOPE_TAKEALL,	// like a SELECT without WHERE clause
	SCOPE_IK,		// list of IKs
	SCOPE_IKTS,		// list of IKs and (one common) deadline
	SCOPE_PK,		// list of PKs
	SCOPE_TS		// a full time slice (all identities for a given deadline)
};

enum RequestType
{
	REQU_UNDEF = 0,
	REQU_READ,
	REQU_WRITE,
	REQU_ACTION
};

enum DataUserRole
{
	DUR_UNDEF = 0,
	DUR_CLI,
	DUR_CLITMP,
	DUR_SRV
};

// GUI / controller
class WinMain;
class WidSybilView;
typedef WidSybilView * (*SybilViewCreator)(QWidget * parent);
class TransSybilView;
typedef TransSybilView * (*SybilViewTranslationCreator)();
class WidRawData;

// model
struct ColDesc;
class DataModel;
class DataTable;
class DataObject;
class ModTable;
class ModTimeSlice;
class ModTimeline;
typedef std::map<PkType, ModTimeSlice *> ModTimeSlices;
class Request;
class RequestDescriptor;
class DataModel;
class SrvConnection;
class SrvConnectionHttp;
class SrvConnectionLocal;

}

#endif /* SCHEADER_H_ */
